package com.example.smartcity.ui.smartCity.activitytModule

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity.R
import com.example.smartcity.databinding.ActivitySm2Binding
import com.example.smartcity.logic.utils.BaseActivity
import com.example.smartcity.ui.home.fragment.fragment1
import com.example.smartcity.ui.home.fragment.fragment3
import com.example.smartcity.ui.home.fragment.fragment4
import com.example.smartcity.ui.smartCity.fragment.SmFragment_2
import com.google.android.material.tabs.TabLayoutMediator

class SmActivity_2 : BaseActivity() {
    private lateinit var mBinding: ActivitySm2Binding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivitySm2Binding.inflate(layoutInflater)
        setContentView(mBinding.root)
        title = "党员学习"
        supportActionBar?.setDisplayHomeAsUpEnabled(true)

        // 设置适配器
        mBinding.Sm2ViewPager.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount() = 3

            override fun createFragment(position: Int): Fragment = when(position){
                0 -> SmFragment_2()
                1 -> fragment3()
                2 -> fragment4()
                else -> SmFragment_2()
            }
        }

        TabLayoutMediator(mBinding.Sm2TabLayout, mBinding.Sm2ViewPager){ tab, position ->
            when(position){
                0 -> tab.text = "推荐视频"
                1 -> tab.text = "政策解读"
                2 -> tab.text = "经济发展"
            }
        }.attach()
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        this@SmActivity_2.finish()
        return super.onOptionsItemSelected(item)
    }
}